import request from '@/utils/request'

// 分页查询文件列表
export function getFileList(currentPage, pageSize, queryParams) {
  return request({
    url: `/api/file/page/${currentPage}/${pageSize}`,
    method: 'get',
    params: queryParams
  })
}

// 单文件上传
export function uploadFile(formData) {
  return request({
    url: '/api/file/upload',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 批量文件上传
export function uploadFiles(formData) {
  return request({
    url: '/api/file/upload/batch',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 下载文件
export function downloadFile(fileId) {
  return request({
    url: `/api/file/download/${fileId}`,
    method: 'get',
    responseType: 'blob'
  })
}

// 预览文件
export function previewFile(fileId) {
  return request({
    url: `/api/file/preview/${fileId}`,
    method: 'get',
    responseType: 'blob'
  })
}

// 删除文件
export function deleteFile(fileId) {
  return request({
    url: `/api/file/${fileId}`,
    method: 'delete'
  })
}

// 根据关联信息获取文件列表
export function getFilesByRelatedInfo(relatedType, relatedId) {
  return request({
    url: `/api/file/related/${relatedType}/${relatedId}`,
    method: 'get'
  })
}

// 获取用户文件列表
export function getUserFiles(userId) {
  return request({
    url: `/api/file/user/${userId}`,
    method: 'get'
  })
}

// 获取用户文件统计信息
export function getUserFileStatistics(userId) {
  return request({
    url: `/api/file/statistics/${userId}`,
    method: 'get'
  })
}

// 图片压缩
export function compressImage(formData) {
  return request({
    url: '/api/file/image/compress',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 生成缩略图
export function generateThumbnail(formData) {
  return request({
    url: '/api/file/image/thumbnail',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 添加水印
export function addWatermark(formData) {
  return request({
    url: '/api/file/image/watermark',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 获取图片信息
export function getImageInfo(formData) {
  return request({
    url: '/api/file/image/info',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}